<?php
if (!defined("MCTDESIGN")) die("# ");
//require_once './_classes/_class_upload.php';
//$upLoad = new UploadFile;
if (isset($_POST['delete']) || isset($_POST['flag']) && $_POST['flag'] == 1) {

	$total = isset($_POST["total"]) ? intval($_POST["total"]) : 0;

 	for($i=1;$i<=$total;$i++){

		$checkbox[$i] = isset($_POST["checkbox_$i"]) ? $_POST["checkbox_$i"] : '';

		if (!empty($checkbox[$i])) {            
            $anyDB->query = "delete from ".$tb_fix."_tour where tou_category = '".$checkbox[$i]."'";
			$anyDB->query("DELETE FROM ".$tb_fix."_tour_menu WHERE tme_id='".$checkbox[$i]."'");
		}

	}

	$html_body = _html_trans("Xóa Tour thành công !");

	return false;

}
if (isset($_POST['add'])) {
    $t_root = $_POST['t_root']; 
    if($t_root == 1) {
        $t_title = isset($_POST["tour_title_nn"]) ? fixquotes(stripslashes($_POST["tour_title_nn"])) : "";
        $t_parent_id = $_POST["tour_nuocngoai_id"];     
    }else{
        $t_title = isset($_POST["tour_title_tn"]) ? fixquotes(stripslashes($_POST["tour_title_tn"])) : "";
        $t_parent_id = 0;
    }        	
	if (empty($t_title)) {

		$html_body = _html_trans("Bạn phải nhập tên Tour !");

		return false;

	}
    $isEdit = $_POST['isEdit'];
    
    if($isEdit){ // EDIT
        $tourID = $_POST['t_id'];
        $sql = "update ".$tb_fix."_tour_menu set tme_title = '$t_title', tme_parent_id = '$t_parent_id' where tme_id = '$tourID'";
        //echo $sql; die();
    }else{
        $sql = "insert into ".$tb_fix."_tour_menu 
                values (0,'$t_title','','$t_parent_id','$t_root',1,0)";    
    }
    $q = $anyDB->query($sql);
    if($q){
        if($isEdit){
            $html_body = _html_trans(" Đã sửa danh mục Tour !");    
        }else{
            $html_body = _html_trans("Thêm danh mục Tour mới thành công !");
        }
            
    }else{
        $html_body = _html_trans("Xảy ra lỗi. Vui lòng liên hệ Webmaster !");
    }
	

	return false;

}
if(isset($_GET['del']) && $_GET['del'] == 'true'){
    $id = intval($_GET['id']);
    $act = $_GET['act'];
    if($act == 'list'){
        $sql = "select mti_url from ".$tb_fix."_tour_img where tou_id = $id";
        $r = $anyDB->getAll($anyDB->query($sql));
        foreach ($r as $k=>$v){
            $tour_img_url = $v['mti_url'];
            @unlink($tour_img_url);
        }
        $anyDB->query("DELETE FROM ".$tb_fix."_tour WHERE tou_id=$id");
        $anyDB->query("DELETE FROM ".$tb_fix."_tour_img WHERE tou_id=$id");;
       $html_body = _html_trans("Xóa Tour thành công !","admin.php?obj=Tour&act=list");    
    }else{
        $anyDB->query("DELETE FROM ".$tb_fix."_tour_order WHERE tod_id=$id");
        $html_body = _html_trans("Xóa đặt Tour thành công !","admin.php?obj=Tour&act=order"); 
    }
    

	return false;             
}
if (isset($_POST['delete_more_tour'])) {

	$total = isset($_POST["total"]) ? intval($_POST["total"]) : 0;

 	for($i=1;$i<=$total;$i++){

		$checkbox[$i] = isset($_POST["checkbox_$i"]) ? $_POST["checkbox_$i"] : '';

		if (!empty($checkbox[$i])) {
            $tour_id = $checkbox[$i];
            $sql = "select mti_url from ".$tb_fix."_tour_img where tou_id = $tour_id";
            $r = $anyDB->getAll($anyDB->query($sql));
            foreach ($r as $k=>$v){
                $tour_img_url = $v['mti_url'];
                @unlink($tour_img_url);
            }
			$anyDB->query("DELETE FROM ".$tb_fix."_tour WHERE tou_id=$tour_id");
            $anyDB->query("DELETE FROM ".$tb_fix."_tour_img WHERE tou_id=$tour_id");
            $anyDB->query("DELETE FROM ".$tb_fix."_tour_order WHERE tou_id=$tour_id");
		}

	}

	$html_body = _html_trans("Xóa Tour thành công !","admin.php?obj=Tour&act=list");

	return false;

}
if (isset($_POST['delete_more_tour_order'])) {
	$total = isset($_POST["total"]) ? intval($_POST["total"]) : 0;
 	for($i=1;$i<=$total;$i++){
		$checkbox[$i] = isset($_POST["checkbox_$i"]) ? $_POST["checkbox_$i"] : '';
		if (!empty($checkbox[$i])) {
            $tour_order_id = $checkbox[$i];
            $anyDB->query("DELETE FROM ".$tb_fix."_tour_order WHERE tod_id=$tour_order_id");
		}
	}
	$html_body = _html_trans("Xóa đặt Tour thành công !","admin.php?obj=Tour&act=order");
	return false;
}
if (isset($_POST['order'])) {

	$total = isset($_POST["total"]) ? intval($_POST["total"]) : 0;

    for ($i=1;$i<=$total;$i++)

      {

           $cat_id    = isset($_POST["order_id_$i"])    ? $_POST["order_id_$i"]    : 0;

           $cat_order = isset($_POST["order_$i"]) ? $_POST["order_$i"] : 0;

           if ( ($cat_id>0)&&($cat_order>0) )

           {		

				$mysql->query("UPDATE ".$tb_fix."_tour_menu SET tme_order='$cat_order' WHERE tme_id='".$cat_id."'");

           }

    }

	$html_body = _html_trans("Đã cập nhật thứ tự các danh mục Tour !");

	return false;

}

if(isset($_POST['add_tour'])){
    $rTour = $_POST['tour_root'];
    if($_POST['isEditTour']){
        $tou_id = $_POST['tour_id'];
        $urlReturn = "admin.php?obj=Tour&act=edit&id=$tou_id";
    }else{
        $urlReturn = "";
    }
    //test($_FILES['tour_img'],1);
    $titTour = fixquotes(stripslashes($_POST["tour_title"]));
    $codeTour = fixquotes(stripslashes($_POST["tour_code"]));
    $contentTour = fixquotes(stripslashes($_POST["tour_content"]));
    $descTour = fixquotes(stripslashes($_POST["tour_desc"]));
    $phuongtienTour = fixquotes(stripslashes($_POST["tour_phuongtien"]));
    $lichkhoihanh = fixquotes(stripslashes($_POST["tour_calendar"]));
    $imgTour = $_FILES['tour_img']['name'];
    $post_tmp_img = isset($_FILES['tour_img']['tmp_name'] ) ? $_FILES['tour_img']['tmp_name'] : '';
    //$calendarTour = $_POST['tou_calendar_act'];
    $tour_hot = $_POST['tou_hot'];
    $tour_begin = $_POST['time_tour_calendar'];
    $tou_price =  isset($_POST['tour_price']) ? $_POST['tour_price'] : '0';
    $tour_khoihanh =  isset($_POST['tour_khoihanh']) ? $_POST['tour_khoihanh'] : '1';
    if(empty($rTour)) {$html_body = _html_trans(" Chưa chọn Tour chính !",$urlReturn); return false;}
    if(empty($titTour)) {$html_body = _html_trans(" Chưa nhập tên Tour !",$urlReturn); return false;}
    if(empty($codeTour)) {$html_body = _html_trans(" Chưa nhập mã Tour !",$urlReturn); return false;}
    //if(empty($descTour)) {$html_body = _html_trans(" Chưa nhập nội dung tóm tắt !",$urlReturn); return false;}
    if(empty($contentTour)) {$html_body = _html_trans(" Chưa nhập nội dung chi tiết !",$urlReturn); return false;}
    if(!$_POST['isEditTour']){
        if (empty($imgTour) || !check_empty_files_array($_FILES['tour_img'])) {    
        		$html_body = _html_trans("Chưa chọn hình minh họa cho Tour!");    
        		return false;        
            }    
    }
    if($rTour == 1){
        $catTour = $_POST['tour_nuocngoai_id'];
    }else{
        $catTour = $_POST['tour_trongnuoc_id'];
    }
    if(empty($tour_begin)) {$html_body = _html_trans(" Chưa nhập thời gian của Tour !",$urlReturn); return false;}
    if(empty($phuongtienTour)) {$html_body = _html_trans(" Chưa nhập phương tiện của Tour !",$urlReturn); return false;}
    $timenow = time();
    if($_POST['isEditTour']){// sửa tour
        if(check_empty_files_array($_FILES['tour_img'])){ // kiem tra upload hinh moi -> xoa hinh cu
            $q = $anyDB->query("select mti_url from ".$tb_fix."_tour_img where tou_id = '$tou_id'");
            $r = $anyDB->getAll($q);
            foreach($r as $k=>$v){
                $oldImg = $v['mti_url'];
                @unlink($v['mti_url']);    
            }
            $anyDB->query("delete from ".$tb_fix."_tour_img where tou_id = '$tou_id'");
            $file_ary = reArrayFiles($_FILES['tour_img']); // them moi hinh anh tour
            //test($file_ary,1);
            foreach ($file_ary as $file) {
                $fileName =  $file['name'];
                $fileTmpName = $file['tmp_name'];
                if(!empty($fileName)){
                    //$post_img = $upLoad->doMulti("tours",$_FILES['tour_img']);                    
                    $post_img = @uploadIMG($fileName,$fileTmpName,"tours");
                    $q_add_img = array(
                        'mti_url' => "$post_img",
                        'tou_id'=>"$tou_id"
                    );
                    $q_add_query = QueryHelper::insert($tb_fix."_tour_img",$q_add_img);
                    $anyDB->query($q_add_query);
                }
            }            
        }
        // run update
        $sql = "update ".$tb_fix."_tour 
                    set tou_title = '$titTour',
                        tou_category = '$catTour',
                        tou_root_cat_id = '$rTour',
                        tkh_id = '$tour_khoihanh',
                        tou_code = '$codeTour',
                        tou_content = '$contentTour',
                        tou_desc = '$descTour',
                        tou_begin_time 	= '$tour_begin',
                        tou_calendar = '$lichkhoihanh',
                        tou_status = '$tour_hot',
                        tou_price = '$tou_price',
                        tou_phuongtien = '$phuongtienTour'
                    where 
                        tou_id = '$tou_id' 
                        ";   
        $q = $anyDB->query($sql);                
    }else{//thêm mới tour
        $sql = "insert into ".$tb_fix."_tour (tou_title,tou_category,tou_root_cat_id,tkh_id,tou_code,tou_desc,tou_content,tou_price,tou_begin_time,tou_time,tou_calendar,tou_status,tou_phuongtien) 
                values 
                    ('$titTour','$catTour','$rTour','$tour_khoihanh','$codeTour','$descTour','$contentTour','$tou_price','$tour_begin','$timenow','$lichkhoihanh','$tour_hot','$phuongtienTour')";
         //echo $sql;die();           
        $q = $anyDB->query($sql);
        $insertedId=$anyDB->getInsertId();
        $file_ary = reArrayFiles($_FILES['tour_img']); // them moi hinh anh tour
        foreach ($file_ary as $file) {
            $fileName =  $file['name'];
            $fileTmpName = $file['tmp_name'];
            if(!empty($fileName)){
                //$post_img = $post_img = $upLoad->doMulti("tours",$_FILES['tour_img']);
                $post_img = @uploadIMG($fileName,$fileTmpName,"tours");
                $q_add_img = array(
                    'mti_url' => "$post_img",
                    'tou_id'=>"$insertedId"
                );
                $q_add_query = QueryHelper::insert($tb_fix."_tour_img",$q_add_img);
                $anyDB->query($q_add_query);
            }
        }
    }
    
    if($q){
        if($_POST['isEditTour']){
            $html_body =_html_trans(" Cập nhật Tour thành công!",'?obj=Tour&act=list');
        }else{
            $html_body =_html_trans(" Thêm Tour mới thành công!");    
        }
        
    }else{
        $html_body =_html_trans(" Lỗi trong quá trình sử lý, liên hệ Webmaster !");
    }
    return false;
}

function _html_manageCategory()

{

	global $dir_tpl, $tb_fix,$admin_id,$admin_permissions,$_c,$temp,$anyDB;

	$temp_body = $temp;
    // show list tour for add form
    $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = 0 ORDER BY tme_order ASC";
    $q = $anyDB->query($sql);
    $row = $anyDB->getAll();
    foreach($row as $k => $v){
        $tme_id = $v['tme_id'];
        $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = '$tme_id' ORDER BY tme_order ASC";
        $q = $anyDB->query($sql);
        $t = $anyDB->numRows($q);
        if($t > 0){
            $row1 = $anyDB->getAll();
            foreach($row1 as $key => $val){
                $row[$k]['Child'][] = $val;
            }    
        }
        
    }
   //echo "<pre>";print_r($row);die();
    $temp_body->assign("cate",$row);
    // Danh sach tour
    $goRootTour = isset($_GET["rootTour"]) ? fixquotes(stripslashes($_GET["rootTour"])) : 1;
    $temp_body->assign("rTour",$goRootTour);
    $goParentTour = isset($_GET["parentTour"]) ? fixquotes(stripslashes($_GET["parentTour"])) : '0';
    $temp_body->assign("pTour",$goParentTour);
    $sql = "select * from ".$tb_fix."_tour_menu where tme_parent_id = '$goParentTour' and tme_root_id = '$goRootTour' and tme_status = 1 order by tme_order asc";
    $q = $anyDB->query($sql);
    $t = $anyDB->numRows($q);
    if($t>0){
        $r = $anyDB->getAll($q);
        foreach($r as $k=>$v){
            // show num parent tour
            $tme_id = $v['tme_id'];
            $sql = "select count(tme_id) as total_parent from ".$tb_fix."_tour_menu where tme_parent_id = '$tme_id'";            
            $q = $anyDB->query($sql);
            $num = $anyDB->getNext($q);            
            $r[$k]['numParent'] = $num['total_parent'];
        }
        
        $temp_body->assign("listtour",$r);        
    }
    $temp_body->assign("breakcum",breakcum("Quản lý danh mục Tour "));
	$_html = $temp_body->fetch( '_adm_tour_menu.mct' );

	return $_html;

}
function convertDateToData($date){
    $date = explode("/",$date);
    $nDate = $date[0]."-".$date[1]."-".$date[2];
    $sDate = strtotime($nDate);
    return $sDate;
}
function revertDateToShow($dateFromData){
    $d = date("d/m/Y",$dateFromData);
    return $d;
}
function _html_addTour(){
    global $dir_tpl, $tb_fix,$admin_id,$admin_permissions,$temp,$anyDB;
    // List điểm khởi hành
    $sql = "SELECT * FROM ".$tb_fix."_tour_khoihanh where tkh_status = 1 ORDER BY tkh_id ASC";
    $q = $anyDB->query($sql);
    $rows_khoihanh = $anyDB->getAll();
    $temp->assign("khoihanh",$rows_khoihanh);
    // show list tour for add form
    $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = 0 ORDER BY tme_order ASC";
    $q = $anyDB->query($sql);
    $row = $anyDB->getAll();
    foreach($row as $k => $v){
        $tme_id = $v['tme_id'];
        $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = '$tme_id' ORDER BY tme_order ASC";
        $q = $anyDB->query($sql);
        $t = $anyDB->numRows($q);
        if($t > 0){
            $row1 = $anyDB->getAll();
            foreach($row1 as $key => $val){
                $row[$k]['Child'][] = $val;
            }    
        }
        
    }
   //echo "<pre>";print_r($row);die();
    $temp->assign("cate",$row);
    $temp->assign("base_tpl",$dir_tpl);
    $temp->assign("breakcum",breakcum("Thêm Tour mới"));
	$_html = $temp->fetch( '_adm_tour_add.mct' );
	return $_html;
}
function removeCharset($tr){
    $newURL = str_replace(",","",$tr);
    return $newURL;
}
function reArrayFiles($file_post) {
    // sap xep lai mang $_FILE khi su dung multi upload
    $file_ary = array();
    $file_count = count($file_post['name']);
    $file_keys = array_keys($file_post);
    for ($i=0; $i<$file_count; $i++) {
        foreach ($file_keys as $key) {
            $file_ary[$i][$key] = $file_post[$key][$i];
        }
    }
    return $file_ary;
}
function check_empty_files_array($files){
    foreach ($files["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            return true;
        }else{
            return false;
        }
    }
}

function _html_listTour(){
    global $dir_tpl, $tb_fix,$admin_id,$admin_permissions,$anyDB,$temp;
    $temp->assign("breakcum",breakcum("Danh sách Tour"));
    // danh sach tour menu
     $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = 0 ORDER BY tme_order ASC";
    $q = $anyDB->query($sql);
    $row = $anyDB->getAll();
    foreach($row as $k => $v){
        $tme_id = $v['tme_id'];
        $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = '$tme_id' ORDER BY tme_order ASC";
        $q = $anyDB->query($sql);
        $t = $anyDB->numRows($q);
        if($t > 0){
            $row1 = $anyDB->getAll();
            foreach($row1 as $key => $val){
                $row[$k]['Child'][] = $val;
            }    
        }
        
    }
    $temp->assign("cate",$row);
 // phân trang
    $pagegroup_size = 10;
    $page=_POST('p');
    if (!$page||$page==0){$page=1;}
    $limit=_POST('limit');
    if($limit==''||$limit>5) {$limit=10;}
    $offset=($page-1)*$limit;
    $li="limit $offset,$limit";
    $key_word = isset($_GET['key_word']) ? $_GET['key_word']:'';
    $search_Tour_Name = isset($_GET['s_tourname']) ? fixquotes(stripslashes($_GET['s_tourname'])) :'';
    $rootTour = isset($_GET['rTour']) ? fixquotes(stripslashes($_GET['rTour'])) :0;
    $temp->assign("r_tour",$rootTour);
    $temp->assign("k_word",$key_word);
    $temp->assign("s_name",$search_Tour_Name);
    $where = "";
       
    if (empty($key_word)){
        $where = "";   
        $url_paging = "admin.php?obj=Tour&act=list";     
    }else{
        if($key_word == 'hot'){
            $where = " and t.tou_status = 1";
        }else{
            $where = " and c.tme_id = $key_word";    
        }       
        $url_paging = "admin.php?obj=Tour&act=list&rTour=$rootTour&key_word=$key_word";
    }   
    if($search_Tour_Name){
        $where = " and t.tou_title like '%$search_Tour_Name%'";
        $url_paging = "admin.php?obj=Tour&act=list&s_tourname=$search_Tour_Name";
    } 
     $sql = "select count(t.tou_id) as total_r from ".$tb_fix."_tour as t left join ".$tb_fix."_tour_menu as c on t.tou_category = c.tme_id left join ".$tb_fix."_tour_khoihanh as kh on t.tkh_id = kh.tkh_id where 1=1 $where";
             
     $q = $anyDB->query($sql);
     $arr = $anyDB->getNext($q);
     $totalRecord = $arr['total_r']; // tong so ban ghi
     
     //echo $sql;
     $sql = "select t.*,c.tme_title,c.tme_id,kh.tkh_name from ".$tb_fix."_tour as t 
                left join ".$tb_fix."_tour_menu as c on t.tou_category = c.tme_id
                left join ".$tb_fix."_tour_khoihanh as kh on t.tkh_id = kh.tkh_id 
                where 1=1
                $where
                order by tou_id desc
                $li
                ";        
    $q = $anyDB->query($sql);
    $r = $anyDB->getAll($q);
    $temp->assign("tou",$r);
    $pages = pagenavigator($page,$totalRecord,$limit,$pagegroup_size,$url_paging);
    $temp->assign('pages',$pages);
    $temp->assign('dir_tpl',$dir_tpl);
	$_html = $temp->fetch( '_adm_tour_list.mct' );
	return $_html; 
}
function _html_editTour($id){
    global $dir_tpl, $tb_fix,$admin_id,$admin_permissions,$temp,$anyDB;
    $id = (int)$id;
    // List điểm khởi hành
    $sql = "SELECT * FROM ".$tb_fix."_tour_khoihanh where tkh_status = 1 ORDER BY tkh_id ASC";
    $q = $anyDB->query($sql);
    $rows_khoihanh = $anyDB->getAll();
    $temp->assign("khoihanh",$rows_khoihanh);
    // show list tour for add form
    $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = 0 ORDER BY tme_order ASC";
    $q = $anyDB->query($sql);
    $row = $anyDB->getAll();
    foreach($row as $k => $v){
        $tme_id = $v['tme_id'];
        $sql = "SELECT * FROM ".$tb_fix."_tour_menu where tme_parent_id = '$tme_id' ORDER BY tme_order ASC";
        $q = $anyDB->query($sql);
        $t = $anyDB->numRows($q);
        if($t > 0){
            $row1 = $anyDB->getAll();
            foreach($row1 as $key => $val){
                $row[$k]['Child'][] = $val;
            }    
        }
        
    }
    $temp->assign("cate",$row);
    
    // info tour
    $sql = "select * from ".$tb_fix."_tour where tou_id = '$id' limit 0,1";
    $q = $anyDB->query($sql);
    $t = $anyDB->numRows($q);
    if($t > 0){
        $r = $anyDB->getNext($q);
        $tour_id = $r['tou_id'];
        $sql = "select * from ".$tb_fix."_tour_img where tou_id = '$tour_id'";
        $q = $anyDB->query($sql);
        if($anyDB->numRows($q) > 0){
            $row = $anyDB->getAll($q);
            foreach($row as $k=>$v){
                $r['images'][] = $v;
            }
        }
        $tour_title = $r['tou_title'];
        //test($r,1);
        $temp->assign("dir_tpl",$dir_tpl);        
        $temp->assign("tou",$r); 
        $temp->assign("breakcum",breakcum("Sửa Tour: $tour_title"));
    }else{
        $html_body =_html_trans(" Không tìm thấy Tour!");
    }
    
    $temp->assign('base_url',$site_path);
    $temp->assign("base_tpl",$dir_tpl);
	$_html = $temp->fetch( '_adm_tour_edit.mct' );
	return $_html; 
}
// QUAN LY DAT TOUR

function _html_orderTour(){
    global $dir_tpl, $tb_fix,$admin_id,$admin_permissions,$anyDB,$temp;
    $temp->assign("breakcum",breakcum("Danh sách đặt Tour"));
 // phân trang
    $pagegroup_size = 10;
    $page=_POST('p');
    if (!$page||$page==0){$page=1;}
    $limit=_POST('limit');
    if($limit==''||$limit>5) {$limit=10;}
    $offset=($page-1)*$limit;
    $li="limit $offset,$limit";
    $key_word = isset($_GET['getlist']) ? $_GET['getlist']:2;
    $where = "";       
    if (isset($key_word)){
        if(is_numeric($key_word) && $key_word < 2){
            $where = "and o.tod_status = $key_word";    
        }
        if(is_numeric($key_word) && $key_word == 2){
            $where = "";
        }   
        $url_paging = "admin.php?obj=Tour&act=order&getlist=$key_word";     
        $temp->assign('wherelist',$key_word);
    }
     $sql = "select count(o.tod_id) as total_r from ".$tb_fix."_tour_order as o
                left join ".$tb_fix."_tour as t on o.tou_id = t.tou_id
                left join ".$tb_fix."_tour_menu as c on t.tou_category = c.tme_id 
                where 1=1
                $where
                ";         
     $q = $anyDB->query($sql);
     $arr = $anyDB->getNext($q);
     $totalRecord = $arr['total_r']; // tong so ban ghi
     
     //echo $sql;
     $sql = "select t.tou_title, t.tou_id,c.tme_title,c.tme_id,o.tod_time,o.tod_id,o.tod_status from ".$tb_fix."_tour as t 
                right join ".$tb_fix."_tour_menu as c on t.tou_category = c.tme_id
                right join ".$tb_fix."_tour_order as o on o.tou_id = t.tou_id 
                where 1=1
                $where
                order by o.tod_time desc
                $li
                ";    
                //echo $sql;    
    $q = $anyDB->query($sql);
    $r = $anyDB->getAll($q);
    
    foreach($r as $k =>$v){
        $r[$k]['ngaydat'] = gmdates($v['tod_time']);
    }
    $temp->assign("tou",$r);
    $pages = pagenavigator($page,$totalRecord,$limit,$pagegroup_size,$url_paging);
    $temp->assign('pages',$pages);
    $temp->assign('dir_tpl',$dir_tpl);
	$_html = $temp->fetch( '_adm_tour_order.mct' );
	return $_html; 
}
function _html_orderview($id){
    global $dir_tpl, $tb_fix,$admin_id,$admin_permissions,$temp,$anyDB;
    $id = (int)$id;
    if(isset($_POST['update_order_t']) && $_POST['updateOrder'] == 1){
        $todid = (int)$_POST['tod_id'];
        $tod_status = (int)$_POST['tod_status'];
        $sql = "update ".$tb_fix."_tour_order set tod_status = $tod_status where tod_id = $todid";
        $anyDB->query($sql);
        $temp->assign("hasUpdated",1);  
    }
      // info tour
        $sql = "select * from ".$tb_fix."_tour as t
                    left join ".$tb_fix."_tour_order as o
                        on o.tou_id = t.tou_id
                 where o.tod_id = '$id' limit 0,1";
                 //echo $sql;
        $q = $anyDB->query($sql);
        $t = $anyDB->numRows($q);
        if($t > 0){
            $r = $anyDB->getNext($q);
            $tour_id = $r['tou_id'];
            $tour_title = $r['tou_title'];
            //test($r,1);
            $temp->assign("dir_tpl",$dir_tpl);        
            $temp->assign("tou",$r); 
            $temp->assign("breakcum",breakcum("Đặt tour: $tour_title"));
        }else{
            $html_body =_html_trans(" Không tìm thấy thông tin đặt Tour!");
            return false;   
        }    
        $temp->assign('base_url',$site_path);
        $temp->assign("base_tpl",$dir_tpl); 
	$_html = $temp->fetch( '_adm_tour_order_view.mct' );
	return $_html; 
}
switch($act){
    case "add":
        $html_body = _html_addTour();
        break;
    case "list":
        $html_body = _html_listTour();
        break;  
    case "edit":
        $html_body = _html_editTour($id);
        break;   
    case "order":
        $html_body = _html_orderTour($id);
        break; 
    case "orderview":
        $html_body = _html_orderview($id);
        break;                  
    default:
        $html_body = _html_manageCategory();
        break;    
}
/**
 * desc: them, sua, xoa tour
 * finished: 22:00 05/10/2011
 * author: Hoang Dung
 */
?>